package com.yyfax.ph.personal.entrydetail;


import android.text.TextUtils;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

/**
 * 进件明细presenter
 */
public class EntryDetailPresenter extends Presenter<EntryDetailModel, EntryDetailPresenter.View> {
	private static final String TAG = EntryDetailPresenter.class.getSimpleName();
	private View mView;

	public static class Generator implements PresenterFactory<EntryDetailPresenter> {
		@Override
		public EntryDetailPresenter create() {
			return new EntryDetailPresenter();
		}
	}

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new EntryDetailModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public interface View extends IView {
		void getEntryDetailSuccess(List<EntryDetailModel.EntryDetailBean> entryDetailBeens);

		void getEntryDetailFailure(String tips);
	}

	public void getEntryDetails(String subUserId, int pageNo, int pageSize) {
		execute(new EntryDetailModel.EntryDetial(subUserId, String.valueOf(pageNo), String.valueOf(pageSize)), FUNCTIONAL_CODE, false);
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void entryDetailResults(EntryDetailModel.EntryDetailResult result) {
		if (isResponseSuccess(result))
			mView.getEntryDetailSuccess(result.getContent());
		else
			mView.getEntryDetailFailure(TextUtils.isEmpty(result.getMsg()) ? "获取数据失败" : result.getMsg());
	}

}
